package com.wlyuan.index.controller;


import com.wlyuan.index.api.ITestService;
import com.wlyuan.tools.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import lombok.var;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.util.StopWatch;
import org.springframework.web.bind.annotation.*;

@Slf4j
@Api(tags = "测试")
@RestController
@RequiredArgsConstructor
@RequestMapping("/test")
public class TestController {
    @DubboReference(check = false)
    private final ITestService testService;

    @ApiOperation("echo")
    @GetMapping("/concurrency")
    public Result<String> concurrency() {
        return testService.concurrency("echo");
    }

    @ApiOperation("es")
    @PostMapping("/concurrency/es")
    public void writeES() {
        testService.writeES();
    }

    @ApiOperation("message")
    @PostMapping("/message")
    public void message(@RequestParam("messageClass") String messageClass) {
        testService.consume(messageClass);
    }

    @ApiOperation("quotation")
    @PostMapping("/quotation")
    public void quotation() {
        var watch = new StopWatch();
        watch.start();
        testService.quotation();
        watch.stop();
        logger.info("Quotation message cost: {}ms", watch.getTotalTimeMillis());
    }
}
